package main.java.com.riant.test1.demo2;

import java.lang.ref.PhantomReference;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.HashMap;

public class SoftReferenceCache<K,T> {
    private HashMap<K, SoftReference<T>> mCache;

    public SoftReferenceCache() {
        mCache = new HashMap<K, SoftReference<T>>();
    }

    public T get(K k){
        T t=null;
        SoftReference<T> softReference=mCache.get(k);
        if(null!=softReference){
            return softReference.get();
        }
        return null;
    }
    public void put(K key,T t){
        mCache.put(key,new SoftReference<T>(t));
    }
}
